package com.minelx.statementsplus.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class IntList {
	private final int[] elements;

	public IntList(int[] elements) {
		this.elements = elements;
	}

	public List<int[]> split(int partitionsCount) {
		List<int[]> result = new ArrayList<>();
		int lengthOfPartition = (int) Math.ceil(elements.length * 1.0f / partitionsCount);
		for (int at = 0; at < partitionsCount; at++) {
			if (at == partitionsCount - 1) { // last partition
				result.add(Arrays.copyOfRange(elements, at * lengthOfPartition, elements.length));
			} else { // general partition
				result.add(Arrays.copyOfRange(elements, at * lengthOfPartition, (at + 1) * lengthOfPartition));
			}
		}
		return result;
	}

	public static List<int[]> split(int[] source, int count) {
		return new IntList(source).split(count);
	}
}
